﻿var obj = {
    qualitygroupId: '',
    qualitygroupBH: "",
    qualitygroupName: "",
    remark: "",
    createdBy: "",
    createdDate: "",
    updatedBy: "",
    updatedDate: "",
    deletedBy: "",
    deletedDate: "",
    isDeleted: "",
}

layui.use(['table', 'dropdown', 'layer', 'form'], function () {
    var table = layui.table;
    var dropdown = layui.dropdown;
    var layer = layui.layer;
    var form = layui.form;
    var laypage = layui.laypage;
   window.DeviceTan=function DeviceTan() {
         layer.open({
            type: 1, //page 层类型
            area: ['800px', '400px'],
            title: '新增质检组',
            shade: 0.6, //遮罩透明度
            shadeClose: true, //点击遮罩区域，关闭弹层
            maxmin: true, //允许全屏最小化
            anim: 0, //0-6 的动画形式，- 1 不开启
            content: `
                                  <div style="padding: 32px;">
                                           <form class="layui-form layui-form-pane" action="">
                                            <div class="layui-form-item">
                                             <div class="layui-inline">
                                                       <label class="layui-form-label">质检组编号:</label>
                                               <div class="layui-input-block">
                                                         <input type="text" id="qualitygroupBH" lay-verify="required" placeholder="请输入"      autocomplete="off"  class="layui-input">

                                               </div>
                                             </div>
                                             <div class="layui-inline">
                                                       <label class="layui-form-label">质检组名称:</label>
                                               <div class="layui-input-inline">
                                                        <input type="text" id="qualitygroupName" lay-verify="required" placeholder="请输入"   autocomplete="off"  class="layui-input">
                                               </div>
                                             </div>
                                           </div>
                                            <div class="layui-inline">
                                                       <label class="layui-form-label">备注:</label>
                                               <div class="layui-input-inline">
                                                          <input type="text" id="remark" lay-verify="required" placeholder="请输入"   autocomplete="off"  class="layui-input" />

                                               </div>
                                             </div>
                                           </div>
                                   </div>
                                   <div class="layui-form-item">
                                             <button class="layui-btn" lay-submit lay-filter="demo2" onclick="DeviceAdd()">确认</button>
                                   
                                   </div>
                                 </form>
                                   </div>`
        });

        form.render()
    }


    window.DeviceAdd = function DeviceAdd() {
       
        qualitygroupBH = $("#qualitygroupBH").val()
        qualitygroupName = $("#qualitygroupName").val()
        remark = $("#remark").val()
        var model = JSON.stringify({
            "CreatedBy": "",
            "CreatedDate": "",
            "DeletedBy": "",
            "DeletedDate": "",
            "IsDeleted": false,
            "QualitygroupBH": qualitygroupBH,
            "QualitygroupName": qualitygroupName,
            "UpdatedBy": "",
            "UpdatedDate": "",
            "remark": remark,
            "token": "",
        });
   $.ajax({
          
           url: '../Quality/GetAllocationAdd',
            type: 'post',
            data: {
                CreatedBy: "",
                DeletedBy: "",
                DeletedDate: "",
                IsDeleted: false,
                QualitygroupBH: qualitygroupBH,
                QualitygroupName: qualitygroupName,
                UpdatedBy: "",
                UpdatedDate: "",
                remark: remark,
                token: "",
            },
            //contentType: 'application/json',
            success: function (res) {
                console.log(res)
                var res = JSON.parse(res)
                if (res.data > 0) {
                    alert("添加成功")
                    window.location.href = '/Quality/QgroupIndexShow'
                }
                else {
                    alert("添加失败")
                }

            }
        })
    }


    $(function () {
        Show();
    });

    window.Show = function Show() {
        layui.use(function () {
      
            var qualitygroupBH = $("#QualitygroupBH").val();
            var qualitygroupName = $("#QualitygroupName").val();

            // 先进行表格的初始渲染
            table.render({
                elem: '#carriertable',  // 表格元素的选择器
                page: {
                    limit: 5,
                    limits: [5, 8, 10]
                },
                cols: [[
                    { type: 'checkbox', fixed: 'left' },
                    { field: 'qualitygroupName', title: '质检组名称' },
                    { field: 'qualitygroupBH', title: '质检组编号' },
                    { field: 'createdDate', title: '创建时间' },
                    { field: 'createdBy', title: '创建人' },
                    { field: 'remark', title: '备注' },
                    {
                        field: '', title: '操作', templet: function (d) {
                            return '<a class="layui-btn layui-btn-edit layui-btn-xs" onclick="FanUpdate(' + d.qualitygroupId + ')"><i class="layui-icon layui-icon-edit"></i>编辑</a> ' +
                                '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="IsDel(' + d.qualitygroupId + ')"><i class="layui-icon layui-icon-delete"></i>删除</a>';
                        }

                    }
                ]],
                // 初始时可以先不加载数据，等待 ajax 请求成功后再更新
                data: []
            });

            // 创建表格实例
            $.ajax({
                url: "../Quality/DeviceDo",
                type: "get",
                data: {
                    pageindex: 1,
                    pagesize: 100,
                    token: "",
                    QualitygroupBH: qualitygroupBH,
                    QualitygroupName: qualitygroupName
                },

                success: function (data) {
                    data = JSON.parse(data);
                    console.log(data.data.list);
                    // 在 ajax 请求成功后，使用正确的表格 ID 进行 reload
                    table.reload('carriertable', {
                        page: {
                            limit: 5,
                            limits: [5, 8, 10]
                        },
                        data: data.data.list
                    });
                },
                error: function () {
                    console.log("请求失败");
                }
            });
        });
    }

    window.IsDel = function IsDel(qualitygroupId) {
        var token = localStorage.getItem("token")
        var model = JSON.stringify({
            QualitygroupId: [qualitygroupId],
            DeletedBy: "小红",
            DeletedDate:""
           })
        console.log(model)
        layer.confirm("确认删除吗", function () {
            $.ajax({
                url: '../Quality/IsDelDo',
                data: { model: model, token: token },
                type: 'post',
                success: function (res) {
                    console.log(res);
                    var res = JSON.parse(res);
                    if (res.data > 0) {
                        layer.msg("删除成功", { icon: 1 });
                        Show();
                    } else {
                        layer.msg("删除失败", { icon: 2 });
                    }
                }
            });
        });
    }
    //反填修改

    window.FanUpdate = function FanUpdate(qualitygroupId) {
        $.ajax({
            url: '../Quality/QualityGroudFanDo',
            data: {
                QualitygroupId: qualitygroupId,
                token: "" },
            type: 'Get',
            success: function (res) {
             
                var res = JSON.parse(res)
                console.log(res)
                $.each(res, function () {
                    $("#qualitygroupId").val(this.qualitygroupId)
                    $("#qualitygroupBH").val(this.qualitygroupBH)
                    $("#qualitygroupName").val(this.qualitygroupName)
                    $("#CreatedBy").val(this.createdBy)
                  
                    $("#remark").val(this.remark)
                   obj.qualitygroupId = this.qualitygroupId,
                   obj.qualitygroupBH=this.qualitygroupBH,
                   obj.qualitygroupName=this.qualitygroupName,
                   obj.remark=this.remark,
                   obj.createdBy=this.createdBy,
                   obj.createdDate=this.createdDate,
                   obj.updatedBy=this.updatedBy,
                   obj.updatedDate=this.updatedDate,
                   obj.deletedBy=this.deletedBy,
                   obj.deletedDate=this.deletedDate,
                   obj.isDeleted=this.isDeleted,
                form.render('checkbox'); // 重新渲染checkbox表单元素
                })
            }
        })
        layer.open({
            type: 1, //page 层类型
            area: ['800px', '400px'],
            title: '修改质检组',
            shade: 0.6, //遮罩透明度
            shadeClose: true, //点击遮罩区域，关闭弹层
            maxmin: true, //允许全屏最小化
            anim: 0, //0-6 的动画形式，- 1 不开启
            content: `
                                 <div style="padding: 32px;">
                                           <form class="layui-form layui-form-pane" action="">
                                            <div class="layui-form-item">
                                             <div class="layui-inline">
                                                       <label class="layui-form-label">质检组编号:</label>
                                               <div class="layui-input-block">
                                                         <input type="text" id="qualitygroupBH" lay-verify="required" placeholder="请输入"      autocomplete="off"  class="layui-input">

                                               </div>
                                             </div>
                                             <div class="layui-inline">
                                                       <label class="layui-form-label">质检组名称:</label>
                                               <div class="layui-input-inline">
                                                        <input type="text" id="qualitygroupName" lay-verify="required" placeholder="请输入"   autocomplete="off"  class="layui-input">
                                               </div>
                                             </div>
                                           </div>
                                            <div class="layui-inline">
                                                       <label class="layui-form-label">备注:</label>
                                               <div class="layui-input-inline">
                                                          <input type="text" id="remark" lay-verify="required" placeholder="请输入"   autocomplete="off"  class="layui-input" />

                                               </div>
                                             </div>
                                           </div>
                                   </div>
                                   <div class="layui-form-item">
                                        <button class="layui-btn" lay-submit lay-filter="demo2" onclick="Update()">修改</button>
                                           
                                   </div>
                                 </form>
                                   </div>`,
   });
        form.render()
        window.Update = function Update() {
            qualitygroupBH = $("#qualitygroupBH").val()
            qualitygroupName = $("#qualitygroupName").val()
            remark = $("#remark").val()
            var obj1 = {
                qualitygroupId: '',
                qualitygroupBH: "",
                qualitygroupName: "",
                remark: "",
                createdBy: "",
                createdDate: "",
                updatedBy: "",
                updatedDate: "",
                deletedBy: "",
                deletedDate: "",
                isDeleted: "",
            }
            obj1.qualitygroupId = obj.qualitygroupId
            obj1.qualitygroupBH = qualitygroupBH
            obj1.qualitygroupName = qualitygroupName
            obj1.remark = remark
            obj1.createdBy = obj.createdBy
            obj1.createdDate = obj.createdDate
            obj1.updatedBy = obj.updatedBy
            obj1.updatedDate = obj.updatedDate
            obj1.deletedBy = obj.deletedBy
            obj1.deletedDate = obj.deletedDate
            obj1.isDeleted = obj.isDeleted
            console.log(obj1)
            var token = localStorage.getItem("token")
            $.ajax({
                url: '../Quality/QualityGroupupdateDo',
                type: 'post',
                data: { obj1: obj1, token: token },
                //contentType: 'application/json',
                success: function (res) {
                    console.log(res)
                    var res = JSON.parse(res)
                    if (res.data > 0) {
                        alert("修改成功")
                        window.location.href = '/Quality/QgroupIndexShow'
                    }
                    else {
                        alert("修改失败")
                    }

                }
            })
        }
    }

});



